Notebook to compare results from TS CCC in Human AD project. This will cover comparisons from:

Comparison functions (yes i should be sourcing these, but here we are…)

options(encoding = "UTF-8")
## Function to load and compare objects saved as RDS
## Can be modified to work with RDA as well. Will need to read in objects differently, will need to provide object

## !! Check the tolerance threshold set on line 18 !! ##

# provide paths to rds files
compare_obj <- function(ca_path, cr_path){
  
# generate a list of files to compare based on what was generated by CR  
obj_outs <- list.files(cr_path, pattern = ".rds")

# recursively load and compare objects
for (i in obj_outs) {
  if (file.exists(paste0(cr_path, "/",i))) {
    cat("\n", i, "\n", "\n")
    tmp_CR <- readRDS(paste0(cr_path, "/", i))
    tmp_CA <- readRDS(paste0(ca_path, "/", i))
    print(waldo::compare(tmp_CR, tmp_CA, tolerance = 1e-4))
    cat("\n", "\n", "\n")
 } else {
   cat("\n", i, "\n", "\n")
   # or report that there is not a file
   print(paste0(i, " is not found in independent run output directory "))
   cat("\n", "\n", "\n")
  }
} 
}

## Function to load and stage images side by side for visual comparison

# provide paths to img files and the type of image to look for
compare_figure <- function(ca_path, cr_path, patt){

# generate a list of imgs to compare based on what was generated by CR
fig_outs <- list.files(cr_path, pattern = patt)

# recursively load and stage imgs side-by-side for comparison
for (i in fig_outs) {
  if (file.exists(paste0(cr_path, "/",i))) {
    cat("\n", i,"\n", "\n")
    plots <- lapply(c(paste0(cr_path, "/",i),
                      paste0(cr_path, "/",i)), 
                      function(x) {
    return(grid::rasterGrob(png::readPNG(x)))
  })
  print(gridExtra::grid.arrange(gridExtra::arrangeGrob(grobs = plots, ncol = 2)))
  cat("\n", "\n", "\n")
 } else {
   cat("\n", i,"\n", "\n")
   print(paste0(i, " is not found in independent run output directory"))
   cat("\n", "\n", "\n")
  }
 }
}

## Function to load and compare delimited text
## User needs to provide paths to directories, the delimiter for the files, and the pattern of the file ending
## !! Check the tolerance threshold set on line 18 !! ##

compare_delim <- function(ca_path, cr_path, delim = NULL, patt){
  # generate a list of files to compare based on what was generated by CR  
delim_outs <- list.files(cr_path, pattern = patt)

# recursively load and compare delimited output
for (i in delim_outs) {
  if (file.exists(paste0(cr_path, "/",i))) {
    cat("\n", i, "\n", "\n")
    tmp_CR <- readr::read_delim(paste0(cr_path, "/", i), delim = delim, col_names = FALSE)
    tmp_CA <- readr::read_delim(paste0(ca_path, "/", i), delim = delim, col_names = FALSE)
    print(waldo::compare(tmp_CR, tmp_CA, tolerance = 1e-4))
    cat("\n", "\n", "\n")
 } else {
   cat("\n", i, "\n", "\n")
   # or report that there is not a file
   print(paste0(i, " is not found in independent run output directory "))
   cat("\n", "\n", "\n")
  }
} 
}

02_geo_seurat_prerprocessing.Rmd

objects

cr_path <- here::here("results", "intermediate_outputs", "geo")
ca_path <- here::here("results", "ac_results", "intermediate_outputs", "geo")
compare_obj(ca_path = ca_path, cr_path = cr_path)
## 
##  all_marker_genes.rds 
##  
## v No differences
## 
##  
## 

figures

cr_path <- here::here("results", "ac_results", "final_outputs", "geo")
ca_path <- here::here("results", "final_outputs", "geo")
compare_figure(ca_path = ca_path, cr_path = cr_path, patt = ".png")
## 
##  UMAP_final.png 
## 

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name            grob
## 1 1 (1-1,1-1) arrange gtable[arrange]
## 
##  
## 

01_vine_seurat_preprocessing.Rmd

objects

cr_path <- here::here("results", "intermediate_outputs", "vine")
ca_path <- here::here("results", "ac_results", "intermediate_outputs", "vine")
compare_obj(ca_path = ca_path, cr_path = cr_path)
## 
##  all_marker_genes.rds 
##  
## v No differences
## 
##  
## 

figures

cr_path <- here::here("results", "ac_results", "final_outputs", "vine")
ca_path <- here::here("results", "final_outputs", "vine")
compare_figure(ca_path = ca_path, cr_path = cr_path, patt = ".png")
## 
##  UMAP_final.png 
## 

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name            grob
## 1 1 (1-1,1-1) arrange gtable[arrange]
## 
##  
## 
cr_path <- here::here("results", "ac_results", "intermediate_outputs", "vine")
ca_path <- here::here("results", "intermediate_outputs", "vine")
compare_figure(ca_path = ca_path, cr_path = cr_path, patt = ".png")
## 
##  UMAP_subcluster.png 
## 

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name            grob
## 1 1 (1-1,1-1) arrange gtable[arrange]
## 
##  
## 

03_vinecortex_seurat_preproccessing.Rmd

objects

cr_path <- here::here("results", "intermediate_outputs", "vine_cortex")
ca_path <- here::here("results", "ac_results", "intermediate_outputs", "vine_cortex")
compare_obj(ca_path = ca_path, cr_path = cr_path)
## 
##  all_marker_genes.rds 
##  
## v No differences
## 
##  
## 

figures

cr_path <- here::here("results", "ac_results", "final_outputs", "vine_cortex")
ca_path <- here::here("results", "final_outputs", "vine_cortex")
compare_figure(ca_path = ca_path, cr_path = cr_path, patt = ".png")
## 
##  UMAP_final.png 
## 

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name            grob
## 1 1 (1-1,1-1) arrange gtable[arrange]
## 
##  
## 
cr_path <- here::here("results", "ac_results", "intermediate_outputs", "vine_cortex")
ca_path <- here::here("results", "intermediate_outputs", "vine_cortex")
compare_figure(ca_path = ca_path, cr_path = cr_path, patt = ".png")
## 
##  UMAP_subcluster.png 
## 

## TableGrob (1 x 1) "arrange": 1 grobs
##   z     cells    name            grob
## 1 1 (1-1,1-1) arrange gtable[arrange]
## 
##  
##